package com.zhxt.web.controller.zhxtapi;

import com.zhxt.common.annotation.Log;
import com.zhxt.common.core.controller.BaseController;
import com.zhxt.common.core.domain.AjaxResult;
import com.zhxt.common.core.page.TableDataInfo;
import com.zhxt.common.enums.BusinessType;
import com.zhxt.system.domain.ZhxtContribute;
import com.zhxt.system.service.IZhxtContributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 管理系统-凌烟阁信息维护
 */

@RestController
@RequestMapping("/zhxtapi/contribute")
public class ContributeController extends BaseController {
    //凌烟阁处理
    @Autowired
    private IZhxtContributeService iZhxtContributeService;

    /**
     * 凌烟阁分页查询
     */
    @PostMapping("/getContributeList")
    public TableDataInfo getContributeList(ZhxtContribute zhxtContribute){
        startPage();
        List<ZhxtContribute> zhxtContributeList = iZhxtContributeService.getZhxtContributeList(zhxtContribute);
        return getDataTable(zhxtContributeList);
    }

    /**
     * 新增凌烟阁
     */
    @Log(title = "pc-新增名人堂", businessType = BusinessType.INSERT)
    @PostMapping("/addContribute")
    public AjaxResult addContribute(ZhxtContribute zhxtContribute){
        AjaxResult ajax=AjaxResult.success();
        if(zhxtContribute.getName().isEmpty()){
            return AjaxResult.error("姓名不能为空");
        }else if(zhxtContribute.getTjname().isEmpty()){
            return AjaxResult.error("机构不能为空");
        }else if(zhxtContribute.getGwname().isEmpty()){
            return AjaxResult.error("岗位不能为空");
        }else if(zhxtContribute.getDesc().isEmpty()){
            return AjaxResult.error("内容不能为空");
        }
        int aNum=iZhxtContributeService.addContribute(zhxtContribute);
        if(aNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","新增成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","新增失败");
        }
        return ajax;
    }

    /**
     * 修改凌烟阁
     */
    @Log(title = "pc-修改名人堂", businessType = BusinessType.UPDATE)
    @PostMapping("/updateContribute")
    public AjaxResult updateContribute(ZhxtContribute zhxtContribute){
        AjaxResult ajax=AjaxResult.success();
        if(zhxtContribute.getName().isEmpty()){
            return AjaxResult.error("姓名不能为空");
        }else if(zhxtContribute.getTjname().isEmpty()){
            return AjaxResult.error("机构不能为空");
        }else if(zhxtContribute.getGwname().isEmpty()){
            return AjaxResult.error("岗位不能为空");
        }else if(zhxtContribute.getDesc().isEmpty()){
            return AjaxResult.error("内容不能为空");
        }
        int uNum=iZhxtContributeService.updateContribute(zhxtContribute);
        if(uNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","修改成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","修改失败");
        }
        return ajax;
    }
    /**
     * 删除凌烟阁
     */
    @Log(title = "pc-删除名人堂", businessType = BusinessType.DELETE)
    @PostMapping("/delContribute")
    public AjaxResult delContribute(ZhxtContribute zhxtContribute){
        AjaxResult ajax=AjaxResult.success();
        int dNum=iZhxtContributeService.delContribute(zhxtContribute);
        if(dNum > 0){
            ajax.put("dcode","00");
            ajax.put("dresult","删除成功");
        }else{
            ajax.put("dcode","99");
            ajax.put("dresult","删除失败");
        }
        return ajax;
    }
}
